<template>
  <div class="sales-rank">
    <div class="sales-rank__header">
      <span>场站使用次数排名</span>
    </div>

    <div class="sales-rank__container">
      <!-- <div class="sales-rank__filter">
				<ul>
					<li
						v-for="(item, index) in options.date"
						:key="index"
						:class="{
							active: item.value == selects.type
						}"
						@click="changeDate(item)"
					>
						{{ item.label }}
					</li>
				</ul>

				<div class="hidden-xs-only">
					<el-date-picker
						v-model="selects.date"
						type="datetimerange"
						size="mini"
						range-separator="至"
						start-placeholder="开始日期"
						end-placeholder="结束日期"
						@change="changeDateRa"
					>
					</el-date-picker>
				</div>
			</div> -->

      <ul class="sales-rank__list">
        <li v-for="(item, index) in thisrank" :key="index">
          <span>{{ index+1 }}</span>
          <span class="name" @click="lookDetail(item)">{{ item.name }}</span>
          <span>{{ item.count }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    thisrank: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      selects: {
        date: '',
        type: 'day'
      },
      options: {
        date: [
          // {
          // 	label: "今日",
          // 	value: "day"
          // },
          // {
          // 	label: "本周",
          // 	value: "week"
          // },
          // {
          // 	label: "本月",
          // 	value: "month"
          // },
          // {
          // 	label: "全年",
          // 	value: "year"
          // }
        ]
      }
      // thisrank: []
    }
  },
  mounted() {
    console.log('this.ranklist', this.thisrank)
    // this.getInfo();

    // console.log('rank', this.thisrank)
  },

  methods: {
    lookDetail(row) {
      console.log('row', row)

      this.$router.push({
        path: '/lock',
        query: {
          id: row.id
        }
      })
    },
    changeDate(item) {
      this.selects.type = item.value
    },
    changeDateRa() {
      // console.log('selects.date', this.selects.date)
      // this.$service.home.getInfo({
      // 	startTime: this.selects.date[0],
      // 	endTime: this.selects.date[1]
      // }).then((res) => {
      // 	// this.topInfo = res.topInfo.info4
      // 	// this.per = parseInt((this.topInfo.handled / this.topInfo.workorderNum) * 100)
      // });
    },
    getInfo() {
      // this.$service.home.getInfo().then((res) => {
      //   let arr = []
      //   this.rank = res.rank
      //   for (const key in this.rank) {
      //     arr.push(this.rank[key])
      //   }

      //   arr = arr.sort(this.compare('count'))
      //   arr = arr.reverse()
      //   this.thisrank = arr
      //   console.log('this.thisrank', this.thisrank)
      // })
    },
    compare(label) {
      return function(a, b) {
        var value1 = a[label]
        var value2 = b[label]
        return value1 - value2
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.sales-rank {
	&__header {
		display: flex;
		align-items: center;
		height: 50px;
		font-size: 15px;
		font-weight: bold;
		color: $color-main;
		padding: 0 20px;
	}

	&__container {
		padding: 0 20px;
	}

	&__filter {
		display: flex;
		align-items: center;
		height: 40px;

		ul {
			display: flex;
			justify-content: space-between;
			width: 200px;
			margin-right: 20px;

			li {
				list-style: none;
				font-size: 14px;
				cursor: pointer;
				color: #d8d8d8;

				&.active {
					color: $color-main;
				}

				&:not(.active):hover {
					color: #999;
				}
			}
		}
	}

	&__list {
		height: 260px;

		li {
			display: flex;
			align-items: center;
			height: 52px;
			list-style: none;
			font-size: 13px;
			cursor: pointer;

			span {
				&:first-child {
					display: inline-block;
					height: 14px;
					width: 14px;
					border-radius: 14px;
					text-align: center;
					line-height: 14px;
					font-size: 12px;
				}

				&:nth-child(2) {
					flex: 1;
					margin: 0 10px;
					letter-spacing: 0.5px;
					color: #222;
					@include text_ellipsis();
				}
			}

			&:nth-last-child(n + 3) {
				span {
					&:first-child {
						background-color: $color-main;
						color: #fff;
					}
				}
			}

			&:hover {
				span:nth-child(2) {
					text-decoration: underline;
				}
			}
		}
	}
}

.sales-rank__list{
	height: 300px;
    overflow-y: hidden;
}

.sales-rank__list li{
	height: 45px;
}

.name:hover{
	color: #409EFF !important;
}
</style>
